﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SnippetBox.Core.Data.Models;
using SnippetBox.Core.Data.Service;

namespace SnippetBox.Web.Areas.Manage.Models {
    public class SnippetModel {
        public Snippet Snippet { get; set; }

        public SnippetModel() {
            CategoryList = new CategoryService().GetCategoryList();
            if (Snippet != null)
                CategoryId = Snippet.Category.CategoryId;
        }

        public SnippetModel(Snippet snippet) : this() {
            Snippet = snippet;
            if (Snippet != null)
                CategoryId = Snippet.Category.CategoryId;
        }

        public IEnumerable<SelectListItem> CategoryList { get; set; }
        
        [Required(ErrorMessage = "Please select a category")]
        public int? CategoryId { get; set; }
    }
}